/**
 * Copyright 2015-现在 广州市领课网络科技有限公司
 */
package com.dhcc.bpm.business.utils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.Serializable;

/**
 * 接口返回对象实体
 * 
 * @author Mlf
 * @param <T>
 */
public final class JsonBaseResult<T extends Serializable> implements Serializable {

	private static final Logger logger = LoggerFactory.getLogger(JsonBaseResult.class);

	private static final long serialVersionUID = 1L;

	/**
	 * 错误码
	 */
	private String code = Status.BUSINESS_FAIL.getCode();

	/**
	 * 错误信息
	 */
	private String msg = null;

	/**
	 * 返回结果实体
	 */
	private Object data = null;

	public JsonBaseResult() {
	}

	private JsonBaseResult(String code, String msg, Object data) {
		this.code = code;
		this.msg = msg;
		this.data = data;
	}

	public static <T extends Serializable> JsonBaseResult<T> error(String msg) {
		logger.debug("返回错误：code={}, msg={}", Status.BUSINESS_FAIL.getCode(), msg);
		return new JsonBaseResult<T>( Status.BUSINESS_FAIL.getCode(), msg, null);
	}

	public static <T extends Serializable> JsonBaseResult<T> error(Object data) {
		return new JsonBaseResult<T>(Status.BUSINESS_FAIL.getCode(), "", data);
	}

	public static <T extends Serializable> JsonBaseResult<T> error(String msg,Object data) {
		logger.debug("返回错误：code={}, msg={}", Status.BUSINESS_FAIL.getCode(), msg);
		return new JsonBaseResult<T>( Status.BUSINESS_FAIL.getCode(), msg, data);
	}

	public static <T extends Serializable> JsonBaseResult<T> error(String code, String msg,Object data) {
		return new JsonBaseResult<T>(code, msg, data);
	}

	public static <T extends Serializable> JsonBaseResult<T> error(Status resultEnum) {
		logger.debug("返回错误：code={}, msg={}", resultEnum.getCode(), resultEnum.getMsg());
		return new JsonBaseResult<T>(resultEnum.getCode(), resultEnum.getMsg(), null);
	}

	public static <T extends Serializable> JsonBaseResult<T> error(String code, String msg) {
		logger.debug("返回错误：code={}, msg={}", code, msg);
		return new JsonBaseResult<T>(code, msg, null);
	}

	public static <T extends Serializable> JsonBaseResult<T> success(Object data) {
		return new JsonBaseResult<T>(Status.BUSINESS_SUCCESS.getCode(), "", data);
	}

	public static <T extends Serializable> JsonBaseResult<T> success(String code, String msg,Object data) {
		return new JsonBaseResult<T>(code, msg, data);
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public Object getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

	@Override
	public String toString() {
		return "Result [code=" + code + ", msg=" + msg + ", data=" + data + "]";
	}

	public void setData(Object data) {
		this.data = data;
	}
	

}
